package com.swsc.solarverse.service.forward.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.swsc.solarverse.common.enums.DeviceSourceEnums;
import com.swsc.solarverse.common.util.BizAssert;
import com.swsc.solarverse.dao.entity.forward.ForwardDeviceInfoDO;
import com.swsc.solarverse.dao.mapper.forward.ForwardDeviceInfoMapper;
import com.swsc.solarverse.service.forward.IForwardDeviceInfoService;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author AutoGenerator
 * @since 2022-08-23
 */
@Service
public class ForwardDeviceInfoServiceImpl extends ServiceImpl<ForwardDeviceInfoMapper, ForwardDeviceInfoDO> implements IForwardDeviceInfoService {


    @Override
    public ForwardDeviceInfoDO getForwardDeviceInfo(Integer tenantNo, Integer organNo, Long deviceId) {
        return getForwardDeviceInfo(tenantNo, organNo, deviceId, DeviceSourceEnums.getDefaultUiSource());
    }

    @Override
    public ForwardDeviceInfoDO getForwardDeviceInfo(Integer tenantNo, Integer organNo, Long deviceId, String deviceSource) {
        return baseMapper.selectOne(Wrappers.lambdaQuery(ForwardDeviceInfoDO.class)
                .eq(null != tenantNo, ForwardDeviceInfoDO::getTenantNo, tenantNo)
                .eq(ForwardDeviceInfoDO::getOrganNo, organNo)
                .eq(ForwardDeviceInfoDO::getDeviceId, deviceId)
                .eq(ForwardDeviceInfoDO::getDeviceSource, deviceSource));
    }

    @Override
    public ForwardDeviceInfoDO checkForwardDeviceInfo(Integer tenantNo, Integer organNo, Long deviceId) {
        return checkForwardDeviceInfo(tenantNo, organNo, deviceId, DeviceSourceEnums.getDefaultUiSource());
    }

    @Override
    public ForwardDeviceInfoDO checkForwardDeviceInfo(Integer tenantNo, Integer organNo, Long deviceId, String deviceSource) {
        ForwardDeviceInfoDO deviceInfoDo = getForwardDeviceInfo(tenantNo, organNo, deviceId, deviceSource);
        BizAssert.isFalse(null == deviceInfoDo, "转发数据设备不存在");
        return deviceInfoDo;
    }
}
